home *** CD-ROM | disk | FTP | other *** search
/ Shareware Super Platinum 8 / Shareware Super Platinum 8.iso / mac / PROGTOOL / PASSDK30.ZIP;1 / DISK1.ZIP / PAS / SUBS / MIXERS / FYI / ORIGMIXC.C < prev   
Encoding:
C/C++ Source or Header  |  1992-06-28  |  10.9 KB  |  413 lines

  1.  
  2. ;    /*\
  3. ;---|*|----====< MIXERC.C >====----
  4. ;---|*|
  5. ;---|*| Initialize and setup the access to the mixers, volume, filter, etc
  6. ;---|*|
  7. ;---|*| Copyright (c) 1991, Media Vision, Inc. All rights reserved
  8. ;---|*|
  9. ;    \*/
  10.  
  11. #include <stdio.h>
  12. #include <stdlib.h>
  13. #include "mixbin.h"                 // the actual mixer code
  14. #include "state.h"                  // the state structure
  15.  
  16. ;   /*\
  17. ;---|*|---------------====< Programming Caveat >====--------------\
  18. ;---|*|                                                           |
  19. ;---|*| This code is provided for documentation ONLY. It has been |
  20. ;---|*| replaced by MIXERC.C. Please use the newer body of code   |
  21. ;---|*| for all your development, thus avoiding hardware depend-  |
  22. ;---|*| encies.                                                   |
  23. ;---|*|                                                           |
  24. ;---|*|---------------====< Programming Caveat >====--------------/
  25. ;    \*/
  26.  
  27.         int  ThePASDMAChannel = 0;    // DMA channel
  28.         int  ThePASIRQChannel = 0;    // IRQ channel
  29.  
  30.         static int dummyroutine        ();
  31.  
  32.         int (far *MVSetMixerFunction)  () = 0;
  33.         int (far *MVSetVolumeFunction) () = 0;
  34.         int (far *MVSetFilterFunction) () = 0;
  35.         int (far *MVSetCrossChannel)   () = 0;
  36.         int (far *MVGetMixerFunction)  () = 0;
  37.         int (far *MVGetVolumeFunction) () = 0;
  38.         int (far *MVGetFilterFunction) () = 0;
  39.         int (far *MVGetCrossChannel)   () = 0;
  40.         int (far *MVRealSoundSwitch)   () = 0;
  41.         int (far *MVFMSplitSwitch)       () = 0;
  42.  
  43. #define STATICDRIVER    0x0000        // The static driver is loaded.
  44. #define DOSDRIVER        0x0001        // The DOS driver is loaded.
  45. #define DISKDRIVER        0x0002        // The Disk resident driver is loaded.
  46.  
  47.         extern struct MVState far *mvhwShadowPointer;
  48.         static struct MVState far *(far *MVMixerHWStateFunction)()       = 0;
  49.                struct MVState far *MVMixerHWState(struct MVState far *);
  50.  
  51. ////
  52. ////;    /*\
  53. ////;---|*|----====< test code >====----
  54. ////;---|*|
  55. ////;---|*| this is test code to be removed
  56. ////;---|*|
  57. ////;    \*/
  58. //// int main()
  59. //// {
  60. ////
  61. ////    // In each of the following calls, MVInitMixerCode will search for
  62. ////    // the DOS driver, "MVSOUND.SYS". If found, all succeeding calls to
  63. ////    // the mixers will be routed through MVSOUND.SYS. If the DOS driver
  64. ////    // is not found, then either the DISK based version, or the static
  65. ////    // version will be used. To select the DISK based version, pass a
  66. ////    // path to MVInitMixerCode. Any pointer (other than a NULL) will tell
  67. ////    // the routine to load the driver from the disk. NOTE: If loading from
  68. ////    // the disk fails, then the static driver will be used.
  69. ////
  70. ////    //
  71. ////    // EXAMPLE #1 - The following will attempt to
  72. ////    //                load the driver from the disk.
  73. ////
  74. ////        MVInitMixerCode ( "." );
  75. ////
  76. ////    //
  77. ////    // EXAMPLE #2 - the following will use the
  78. ////    //                static built-in driver.
  79. ////
  80. ////        MVInitMixerCode ( 0 );
  81. //// }
  82. ////
  83.  
  84. ;    /*\
  85. ;---|*|----====< MVInitMixerCode >====----
  86. ;---|*|
  87. ;---|*| Load link to the DOS driver, or load the mixer code
  88. ;---|*|
  89. ;---|*| Entry Conditions:
  90. ;---|*|     char *path is the path to the disk resident driver.
  91. ;---|*|
  92. ;---|*| Return Value:
  93. ;---|*|      0, the mixer code is using the static driver.
  94. ;---|*|      1, the mixer code is using DOS driver.
  95. ;---|*|      2, the mixer code is using Disk resident driver.
  96. ;---|*|
  97. ;    \*/
  98. int MVInitMixerCode(path)
  99.     char *path;
  100. {
  101. char *p,*p1;
  102. int n,mx,tablelen;
  103. long far *bfp;            // buffer far pointer
  104. long far *tfp;            // table far pointer
  105. long mvver;             // MVSOUND.SYS version #
  106.  
  107. static int retry = 0;    // reentry flag. We will only execute once
  108. static int retcode = 0;
  109.  
  110.     // exit if this code has already been executed
  111.  
  112.         if (retry++)
  113.             return(retcode);
  114.  
  115.     // flush some variables
  116.  
  117.         mx = 0;
  118.  
  119.     _asm {
  120.  
  121.         ; fixup the linked in code to be on a paragraph alignment
  122.  
  123.             push    es
  124.             push    di
  125.             push    si
  126.  
  127.             mov     bx,ds
  128.             mov     es,bx
  129.  
  130.             mov     di,offset code_block    ; get the start of the block
  131.             mov     si,17                    ; # of leading zeros in code_block
  132.             add     si,di                    ; si points to the start
  133.             and     di,0xfff0                ; knock out the low nibble
  134.             add     di,0x10                 ; move back up to a starting place
  135.  
  136.             sbb     ax,ax                   ; overflow carries into the segment
  137.             and     ax,1000h
  138.             add     bx,ax
  139.  
  140.             mov     ax,di                    ; calculate a new segment:offset
  141.             mov     cl,4
  142.             shr     ax,cl
  143.             add     bx,ax                    ; address is bx:0000
  144.  
  145.             mov     cx,2048/2
  146.             cld
  147.             rep movsw
  148.  
  149.             mov     [bfp+0],cx                ; save the new offset
  150.             mov     [bfp+2],bx                ; save the new segment
  151.  
  152.             call    far ptr [bfp]            ; go get the table pointer.
  153.  
  154.             mov     [tfp+0],ax                ; save the function table ptr
  155.             mov     [tfp+2],dx
  156.             mov     byte ptr ThePASDMAChannel,bl    ; save the DMA channel
  157.             mov     byte ptr ThePASIRQChannel,cl    ; save the IRQ channel
  158.  
  159.             pop     si
  160.             pop     di
  161.             pop     es
  162.  
  163.         }
  164.  
  165.         _asm {
  166.  
  167.         ; for small model, we have to update the segments
  168.  
  169.             mov     bx, offset dummyroutine
  170.             mov     word ptr [MVSetMixerFunction+0],bx
  171.             mov     word ptr [MVSetMixerFunction+2],cs
  172.  
  173.             mov     word ptr [MVSetVolumeFunction+0],bx
  174.             mov     word ptr [MVSetVolumeFunction+2],cs
  175.  
  176.             mov     word ptr [MVSetFilterFunction+0],bx
  177.             mov     word ptr [MVSetFilterFunction+2],cs
  178.  
  179.             mov     word ptr [MVSetCrossChannel+0],bx
  180.             mov     word ptr [MVSetCrossChannel+2],cs
  181.  
  182.             mov     word ptr [MVGetMixerFunction+0],bx
  183.             mov     word ptr [MVGetMixerFunction+2],cs
  184.  
  185.             mov     word ptr [MVGetVolumeFunction+0],bx
  186.             mov     word ptr [MVGetVolumeFunction+2],cs
  187.  
  188.             mov     word ptr [MVGetFilterFunction+0],bx
  189.             mov     word ptr [MVGetFilterFunction+2],cs
  190.  
  191.             mov     word ptr [MVGetCrossChannel+0],bx
  192.             mov     word ptr [MVGetCrossChannel+2],cs
  193.  
  194.             mov     word ptr [MVRealSoundSwitch+0],bx
  195.             mov     word ptr [MVRealSoundSwitch+2],cs
  196.  
  197.             mov     word ptr [MVFMSplitSwitch+0],bx
  198.             mov     word ptr [MVFMSplitSwitch+2],cs
  199.  
  200.         ; deterine if the DOS driver is loaded
  201.  
  202.             mov     ax,0xbc00                ; function 0 is for ID
  203.             mov     bx,0x3f3f
  204.             sub     cx,cx
  205.             sub     dx,dx
  206.             int     2fh                     ; go get it...
  207.             xor     bx,cx                    ; combine all registers
  208.             xor     bx,dx
  209.             cmp     bx,0x4d56                ; to form 'MV'
  210.             jnz     mvininodosdriver
  211.  
  212.             mov     ax,0xbc01                ; get the version
  213.             int     2fh
  214.  
  215.             mov     word ptr [mvver+0],bx    ; save the version
  216.             mov     word ptr [mvver+2],cx
  217.  
  218.         ; the DOS driver is loaded, use it's vectors, data, etc
  219.  
  220.             sub     cx,cx                    ; comes back 0 or the entry length
  221.             mov     ax,0xbc03                ; get the vector table
  222.             int     0x2f                    ; from the DOS driver
  223.  
  224.             mov     word ptr [tfp+0],bx     ; save the function pointer offset
  225.             mov     word ptr [tfp+2],dx     ; and segment
  226.             mov     [tablelen],cx
  227.  
  228.             mov     ax,0bc04h                ; get the DMA & IRQ
  229.             int     0x2f                    ; from the DOS driver
  230.  
  231.             mov     byte ptr ThePASDMAChannel,bl    ; DMA channel
  232.             mov     byte ptr ThePASIRQChannel,cl    ; IRQ channel
  233.  
  234.           mvininodosdriver:
  235.  
  236.         }
  237.  
  238.     // if the above code did not find the DOS driver, we will attempt to
  239.     // load the DOS mixer driver program located in the caller's path.
  240.  
  241.         if (retcode != DOSDRIVER) { // no dos driver try the disk version
  242.  
  243.             if (path) {             // if there is a path, try to load it
  244.  
  245.                 // copy the path to working storage
  246.  
  247.                     p1 = p = &code_block[2048-64];// build it at the end of buffer
  248.                     while ((*p++ = *path++) != 0);
  249.  
  250.                 // try to append a '\' to the path
  251.  
  252.                     if (*(p-2) != '\\')
  253.                         *(p-1) = '\\';
  254.  
  255.                 // move the file name
  256.  
  257.                     n = 0;
  258.                     while ((*p++ = "mixer.drv"[n++]) != 0) ;
  259.  
  260.                 // attempt to open the file and read in the driver
  261.  
  262.                     _asm {
  263.  
  264.                         mov     dx,[p1]         ; ds:dx points to the file
  265.                         mov     ax,0x3d00        ; open a file for reading
  266.                         int     0x21
  267.  
  268.                         jc        nofilehere        ; skip out if not found
  269.  
  270.                         push    ds                ; save...
  271.  
  272.                         lds     dx,bfp          ; get the storage pointer
  273.                         mov     bx,ax
  274.                         mov     cx,2048         ; our max size
  275.                         mov     ah,0x3f
  276.                         int     0x21            ; load the driver
  277.  
  278.                         pop     ds                ; ...restore
  279.  
  280.                         pushf
  281.  
  282.                         mov     ah,0x3e         ; close the file
  283.                         int     0x21
  284.  
  285.                         popf                    ; get the success flag
  286.                         jc        nofilehere
  287.  
  288.                         call    far ptr bfp     ; init the code
  289.  
  290.                         mov     [tfp+0],ax        ; save the function table ptr
  291.                         mov     [tfp+2],dx
  292.  
  293.                         mov     byte ptr ThePASDMAChannel,bl ; DMA channel
  294.                         mov     byte ptr ThePASIRQChannel,cl ; IRQ channel
  295.  
  296.                         mov     retcode,DISKDRIVER ; the disk driver is loaded.
  297.  
  298.                     nofilehere:
  299.  
  300.                     }
  301.             }
  302.         }
  303.  
  304.         /* check the static driver to see if we can change the state pointer */
  305.  
  306.         _asm {
  307.  
  308.             push    es
  309.  
  310.             les     bx,bfp
  311.             inc     bx
  312.             inc     bx
  313.             cmp     es:[bx+1],0
  314.             jz        nostatefunc             ; no, skip the pointer save
  315.             mov     [MVMixerHWStateFunction+0],bx ; pointer to state table fetch
  316.             mov     [MVMixerHWStateFunction+2],es ; or set function
  317.         ;
  318.         nostatefunc:
  319.             pop     es
  320.  
  321.         }
  322.  
  323.     // we have the pointer to some table. Now, load each function pointer into
  324.     // the individual far pointers.
  325.  
  326.         if (mvver > 0x30313032)         // ASCII version 0102
  327.             retcode = DOSDRIVER;        // indicate the DOS driver is loaded
  328.  
  329.     // set the first 4 (1st rev of MVSOUND just had 4 functions)
  330.  
  331.         (long) MVSetMixerFunction  = (long) *tfp++;
  332.         (long) MVSetVolumeFunction = (long) *tfp++;
  333.         (long) MVSetFilterFunction = (long) *tfp++;
  334.         (long) MVSetCrossChannel   = (long) *tfp++;
  335.  
  336.     // set the next entries (later revs of MVSOUND had 10 functions)
  337.  
  338.         if (tablelen > 4) {
  339.             (long) MVGetMixerFunction  = (long) *tfp++;
  340.             (long) MVGetVolumeFunction = (long) *tfp++;
  341.             (long) MVGetFilterFunction = (long) *tfp++;
  342.             (long) MVGetCrossChannel   = (long) *tfp++;
  343.             (long) MVRealSoundSwitch   = (long) *tfp++;
  344.             (long) MVFMSplitSwitch       = (long) *tfp;
  345.         }
  346.  
  347.     // setup the local drivers state table pointer
  348.  
  349.         if (retcode != DOSDRIVER)
  350.             MVMixerHWState(mvhwShadowPointer);
  351.  
  352.     // return the code
  353.  
  354.     return retcode;
  355. }
  356.  
  357.  
  358. ;    /*\
  359. ;---|*|----====< MVMixerHWState >====----
  360. ;---|*|
  361. ;---|*| fetch and/or load a pointer to the state table.
  362. ;---|*|
  363. ;---|*| Entry Conditions:
  364. ;---|*|     MVState far *  --  pointer to another table. If NULL (0),
  365. ;---|*|                        the current pointer is only returned. Only
  366. ;---|*|                        non-zero table pointers will be loaded.
  367. ;---|*| Return Value:
  368. ;---|*|      Returns the pointer to the table currently
  369. ;---|*|      used by the mixer code.
  370. ;---|*|
  371. ;    \*/
  372. struct MVState far *MVMixerHWState(tbl)
  373.     struct MVState far *tbl;
  374. {
  375.  
  376.     if (MVMixerHWStateFunction) {    // if there is a function, call it
  377.         _asm {
  378.             mov     ax,[tbl+0]
  379.             mov     dx,[tbl+2]
  380.             call    far ptr [MVMixerHWStateFunction]
  381.             mov     [tbl+0],ax
  382.             mov     [tbl+2],dx
  383.  
  384.         }
  385.     }
  386.     return (tbl);
  387. }
  388.  
  389.  
  390. ;    /*\
  391. ;---|*|----====< static dummyroutine >====----
  392. ;---|*|
  393. ;---|*| This routine no-ops out the function calls in case MVSOUND.SYS
  394. ;---|*| is not loaded.
  395. ;---|*|
  396. ;---|*| Entry Conditions:
  397. ;---|*|     none
  398. ;---|*|
  399. ;---|*| Return Value:
  400. ;---|*|      0
  401. ;---|*|
  402. ;    \*/
  403.  
  404. static int dummyroutine ()
  405. {
  406.     return 0;
  407. }
  408.  
  409.     /*\
  410. ;---|*| End of MIXERC.C
  411.     \*/
  412.  
  413.